//
//  ReportCardItemView.m
//  jzyParents
//
//  Created by 任辰东 on 2022/8/22.
//

#import "ReportCardItemView.h"

@interface ReportCardItemView ()

@property (nonatomic, strong) UILabel *scoreLabel;
@property (nonatomic, strong) UILabel *subjectLabel;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UILabel *classLabel;
@property (nonatomic, strong) UILabel *gradeLabel;
@end

@implementation ReportCardItemView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
        [self setupLayout];
    }
    return self;
}

-(void)configViewWithModel:(Kaoshi_score_listItem *)model
{
    self.scoreLabel.text = model.score;
    self.subjectLabel.text = model.kemu_name;
    self.classLabel.text = [NSString stringWithFormat:@"班级 %@",model.banji_mingci];
    self.gradeLabel.text = [NSString stringWithFormat:@"年级 %@",model.xuexiao_mingci];
}

-(void)setupViews
{
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    self.layer.borderColor = UIColorFromHex(kColorLine).CGColor;
    self.layer.borderWidth = kOnePixel;
    [self addSubview:self.scoreLabel];
    [self addSubview:self.subjectLabel];
    [self addSubview:self.bottomView];
    [self.bottomView addSubview:self.classLabel];
    [self.bottomView addSubview:self.gradeLabel];
}

-(void)setupLayout
{
    [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self).offset(7);
        make.left.right.equalTo(self);
    }];
    
    [self.subjectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.scoreLabel.mas_bottom).offset(5);
        make.left.right.equalTo(self);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.subjectLabel.mas_bottom).offset(5);
        make.left.bottom.right.equalTo(self);
    }];
    
    [self.classLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.bottomView).offset(5);
        make.bottom.equalTo(self.bottomView).offset(-5);
        make.left.equalTo(self.bottomView).offset(0);
        make.width.mas_equalTo((kScreenWidth - 15 *2 - 5*2)/3/2.0);
    }];
    
    [self.gradeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.bottomView).offset(5);
        make.bottom.equalTo(self.bottomView).offset(-5);
        make.right.equalTo(self.bottomView).offset(0);
        make.width.mas_equalTo((kScreenWidth - 15 *2 - 5*2)/3/2.0);
    }];
}

#pragma mark -- lazyload

-(UILabel *)scoreLabel
{
    if (!_scoreLabel) {
        _scoreLabel = [UILabel new];
        _scoreLabel.textColor = UIColorFromHex(0x000000);
        _scoreLabel.font = UIFontSize(14);
        _scoreLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _scoreLabel;
}

-(UILabel *)subjectLabel
{
    if (!_subjectLabel) {
        _subjectLabel = [UILabel new];
        _subjectLabel.textColor = UIColorFromHex(0x666666);
        _subjectLabel.font = UIFontSize(11);
        _subjectLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _subjectLabel;
}

-(UIView *)bottomView
{
    if (!_bottomView) {
        _bottomView = [UIView new];
        _bottomView.backgroundColor = UIColorFromHex(kColorMain);
    }
    return _bottomView;
}

-(UILabel *)classLabel
{
    if (!_classLabel) {
        _classLabel = [UILabel new];
        _classLabel.textColor = UIColorFromHex(0xffffff);
        _classLabel.font = UIFontSize(10);
        _classLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _classLabel;
}

-(UILabel *)gradeLabel
{
    if (!_gradeLabel) {
        _gradeLabel = [UILabel new];
        _gradeLabel.textColor = UIColorFromHex(0xffffff);
        _gradeLabel.font = UIFontSize(10);
        _gradeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _gradeLabel;
}

@end
